<template>
  <el-container>
    <el-header>
      <div class="left-panel">
        <el-button v-if="$AUTH('workflow:defineNodeUser:add')" type="primary" icon="el-icon-plus" @click="add"></el-button>
      </div>
      <div class="right-panel">
        <div class="right-panel-search">
          <!-- 日期时间范围 -->
          <el-date-picker v-model="search.createTime" type="datetimerange" value-format="YYYY-MM-DD HH:mm:ss" start-placeholder="开始日期" end-placeholder="结束日期" style="width: 100%;"></el-date-picker>
          <el-input v-model="search.defineNodeUserId" placeholder="节点执行人" clearable></el-input>
          <el-input v-model="search.defineNodeId" placeholder="节点" clearable></el-input>
          <el-input v-model="search.exeId" placeholder="执行人id" clearable></el-input>
          <el-input v-model="search.exeName" placeholder="执行人名称" clearable></el-input>
          <el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
        </div>
      </div>
    </el-header>
    <el-main class="nopadding">
      <scTable ref="table" :apiObj="apiObj" row-key="defineNodeUserId" @selection-change="selectionChange" stripe>
        <el-table-column type="selection" width="50"></el-table-column>
        <el-table-column label="节点执行人" prop="defineNodeUserId" width="150"></el-table-column>
        <el-table-column label="节点" prop="defineNodeId" width="150"></el-table-column>
        <el-table-column label="执行人id" prop="exeId" width="150"></el-table-column>
        <el-table-column label="执行人名称" prop="exeName" width="150"></el-table-column>
<!--    <el-table-column label="创建时间" prop="createTime" width="150" :formatter="formatDate"></el-table-column>-->
        <el-table-column label="操作" fixed="right" align="right">
          <template #default="scope">
            <el-button v-if="$AUTH('workflow:defineNodeUser:edit')" type="text" size="small" @click="table_edit(scope.row, scope.$index)">编辑</el-button>
            <el-divider direction="vertical"></el-divider>
            <el-button v-if="$AUTH('workflow:defineNodeUser:del')" type="text" size="small" @click="table_del(scope.row, scope.$index)">删除</el-button>
          </template>
        </el-table-column>
      </scTable>
    </el-main>
  </el-container>

  <defineNodeUserEdit-dialog v-if="dialog.defineNodeUserEdit" ref="defineNodeUserEditDialog" @success="handleSaveSuccess" @closed="dialog.defineNodeUserEdit=false"></defineNodeUserEdit-dialog>
</template>

<script>
  import workflowAPI from '@/api/workflow/defineNodeUser';
  import defineNodeUserEditDialog from './defineNodeUserEdit';//1--导入
  export default {
    name: 'defineNodeUser',
    components: {
        defineNodeUserEditDialog//2发布
    },
    data() {
      return {
        dialog: {
          defineNodeUserEdit: false
        },
        apiObj: workflowAPI.defineNodeUser.list,
        selection: [],
        search: {
          keyword: null,
          createTime: null
        }
      }
    },
    methods: {
      //添加
      add(){
        this.dialog.defineNodeUserEdit = true
        this.$nextTick(() => {
          this.$refs.defineNodeUserEditDialog.open()
        })
      },
      //编辑
      table_edit(row){
        this.dialog.defineNodeUserEdit = true
        this.$nextTick(() => {
          this.$refs.defineNodeUserEditDialog.open('edit').setData(row)
        })
      },
      //删除
      async table_del(row){
        var confirm = await this.$confirm('确定删除选中的项吗？', '提示', {
          confirmButtonText: 'ok',
          type: 'warning'
        }).catch(() => {})
        if(confirm !== 'confirm'){
          return false;
        }
        var res = await workflowAPI.defineNodeUser.delete.delete(row.defineNodeUserId);
        if(res.code === 2000){
          this.$refs.table.refresh();
          this.$message.success("删除成功");
        }else{
          this.$alert(res.message, "提示", {type: 'error'});
        }
      },
      //表格选择后回调事件
      selectionChange(selection){
        this.selection = selection;
      },
      //搜索
      upsearch(){
        this.$refs.table.upData(this.search);
      },
      //本地更新数据
      handleSaveSuccess(){
        this.$refs.table.refresh();
      },
      handlePermissionSuccess(){
        this.$refs.table.refresh();
      },
      handleDataSuccess(){
        this.$refs.table.refresh();
      },
      formatDate(row,column) {// 获取单元格数据
        let data = row[column.property];
        if(data == null) {
          return null;
        }
        let dt = new Date(data);
        return dt.getFullYear() + '-' + (dt.getMonth() + 1) + '-' + dt.getDate() + ' ' + dt.getHours() + ':' + dt.getMinutes() + ':' + dt.getSeconds();
      },
    }
  }
</script>
<style>
</style>
